import {Injectable} from '@angular/core';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import {HttpClient, HttpParams} from "@angular/common/http";
@Injectable()
export class HttpService {
    constructor(public http: HttpClient) {
    }

    //返回值要加类型,不然会报错
    register(data): any {
        return this.http.post('/api/register', data).map(res => {
            return res;
        });
    }

    login(data): any {
        let params = new HttpParams({
            fromObject: data
        })
        return this.http.get('/api/login', {
            params: params
        }).map(res => {
            return res;
        })
    }

    auth(userid) {
        let params = new HttpParams({
            fromObject: {
                userid
            }
        });
        return this.http.get('/api/auth', {
            params
        }).map(res => {
            return res;
        })
    }
}
